Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

742a htmx for name select choice field #1004

Conversation

phycodurus
Copy link
Contributor

This PR removes the Submit button and make changing the target name_select ChoiceField update the target fields table:

  1. HTMX attributes were added to the name_select ChoiceField
  2. a GET method was added to the TargetMergeView - if it's an HTMX request triggered by a name_select ChoiceField change, then it updates the table by calling the inclusiontag directly to get it's context and rendering the partial with the new context and return that new HTML. The htmx attributes of the ChoiceField specify (via that hx-target attribute) that the #id_target_merge_fields HTML should be replace.
  3. the #id_target_merge_fields property was assigned to the in the target_fields.html partial.

@phycodurus phycodurus requested review from jchate6 and sglasberg August 5, 2024 20:10
…rge-namesdatasets' into 742a-htmx-for-name-select-choice-field
Copy link
Contributor

@sglasberg sglasberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to run this I got an attribute error:
AttributeError: 'WSGIRequest' object has no attribute 'htmx'

here is the traceback:

File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/core/handlers/base.py", line 199, in _get_response
    response = self.process_exception_by_middleware(e, request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/core/handlers/base.py", line 362, in process_exception_by_middleware
    response = middleware_method(request, exception)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/tom_base/tom_common/middleware.py", line 29, in process_exception
    raise exception
  File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/TOM_explore/env/lib/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sglasberg/dev/tom_base/tom_targets/views.py", line 641, in get
    if request.htmx:
       ^^^^^^^^^^^^
AttributeError: 'WSGIRequest' object has no attribute 'htmx'

Copy link
Contributor

@sglasberg sglasberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add django_htmx to pyproject.toml so that we install this dependency

Could you also please update settings.tmpl with the required intalled app and middleware

@phycodurus phycodurus requested a review from sglasberg August 6, 2024 16:35
Copy link
Contributor

@sglasberg sglasberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good

@sglasberg sglasberg merged commit a915385 into 742-manually-link-two-targets-as-the-same-target-and-merge-namesdatasets Aug 6, 2024
0 of 21 checks passed
@sglasberg sglasberg deleted the 742a-htmx-for-name-select-choice-field branch August 6, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants